package com.lee.leet.everyday.book.basic.array;

import org.springframework.stereotype.Component;

/**
 * @author liylw
 * @date 2021/11/24 10:56
 */
@Component
public class RemoveDuplicatesImpl extends AbsRemoveDuplicates {






    @Override
    public int removeDuplicates(int[] nums) {
        if (nums == null){
            return 0;
        }
        final int length = nums.length;
        if (length==0){
            return 0;
        }
        int last = nums[0];
        int count = 1;
        for (int i = 1; i < nums.length; i++) {
            int current = nums[i];
            if (current !=last){
                last = current;
                nums[count++] = current;
            }
        }
        return count;
    }
}
